package com.design.yjx.observer.custom;

/**
 * @author yuanjianxin
 * @date 2017/8/2 16:51
 * 当前天气情况显示面板实现类
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {
    //温度
    private float temperature;
    //湿度
    private float humidity;
    //气压
    private float pressure;

    private Subject subject;

    //创建对象的时候将观察者注册到主题
    public CurrentConditionsDisplay(Subject subject) {
        this.subject = subject;
        subject.registerObserver(this);
    }

    //模拟展示，打印出参数结果即可
    @Override
    public void display() {
        System.out.println("当前天气情况显示面板---温度:"+temperature+"℃,湿度:"+humidity+"%,气压:"+pressure+"Pa");
    }


    @Override
    public void update(NotifyParams params) {
        this.temperature = params.getTemperature();
        this.humidity = params.getHumidity();
        this.pressure = params.getPressure();
        display();
    }
}
